package com.learn.runner;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 *
 *
 * @author: hbliy
 * @date: 2025/11/5 16:08
 *
 * 默认 commandLineRunner 优先级比 ApplicationRunner 高
 * 可以通过 order 属性指定优先级, 值越小优先级越高
 */
//@Order(1)
@Component
public class MyApplicationRunner implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("MyApplicationRunner.run");
        System.out.println(args);

        // 用 = 绑定（推荐，最清晰）：--arg1=value1 --arg2=value2
        System.out.println("选项参数: " + args.getOptionNames());
        System.out.println("非选项参数: " + args.getNonOptionArgs());

        for (String option : args.getOptionNames()) {
            System.out.println("选项 " + option + " 的值: " + args.getOptionValues(option));
        }
    }
}
